package my.jwds.p206;

import my.jwds.p21.ListNode;

public class ReverseList {

    public static void main(String[] args) {
        ReverseList obj = new ReverseList();
        System.out.println(obj.reverseList(ListNode.to(new int[]{1,2,3,4,5})));
    }

    public ListNode reverseList(ListNode head) {
        ListNode prev = null;
        ListNode curr = head;
        while(head != null){
            head = head.next;
            curr.next = prev;
            prev = curr;
            curr = head;
        }

        return prev;
    }
}
